package com.imooc.concurrency.example.rateLimiter;

import com.google.common.util.concurrent.RateLimiter;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

@Slf4j
public class RateLimiterExample {

    private static RateLimiter rateLimiter = RateLimiter.create(5);

    private static void handler(int i){
        log.info("{}", i);
    }

    public static void main(String[] args) {
        for(int i = 0;i < 100;i ++){
            if(rateLimiter.tryAcquire(200, TimeUnit.MILLISECONDS)) {
                handler(i);
            }
        }
    }
}
